Skip to content

Commit

Permalink
Kingsoft Topgame r668 , little modify for Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-kelly committed Mar 29, 2016
1 parent 5e0a138 commit 4eddeeb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions Examples/Examples.csproj
Expand Up @@ -312,6 +312,7 @@
<Compile Include="Issues\SO18650486.cs" />
<Compile Include="Issues\SO18663361.cs" />
<Compile Include="Issues\SO18695728.cs" />
<Compile Include="Issues\SO19161823.cs" />
<Compile Include="Issues\SO1930209.cs" />
<Compile Include="Issues\SO3083847.cs" />
<Compile Include="Issues\SO3101816.cs" />
Expand Down
3 changes: 2 additions & 1 deletion protobuf-net/Meta/AttributeMap.cs
Expand Up @@ -164,7 +164,8 @@ public override bool TryGet(string key, bool publicOnly, out object value)
{
PropertyInfo prop = member as PropertyInfo;
if (prop != null) {
value = prop.GetValue(attribute, null);
//value = prop.GetValue(attribute, null);
value = prop.GetGetMethod(true).Invoke(attribute, null);
return true;
}
FieldInfo field = member as FieldInfo;
Expand Down
2 changes: 1 addition & 1 deletion protobuf-net/Meta/MetaType.cs
Expand Up @@ -429,7 +429,7 @@ private IProtoTypeSerializer BuildSerializer()
{
MetaType mt = model[surrogate], mtBase;
while ((mtBase = mt.baseType) != null) { mt = mtBase; }
return new SurrogateSerializer(type, surrogate, mt.Serializer);
return new SurrogateSerializer(model, type, surrogate, mt.Serializer);
}
if (IsAutoTuple)
{
Expand Down
6 changes: 4 additions & 2 deletions protobuf-net/Serializers/PropertyDecorator.cs
Expand Up @@ -66,14 +66,16 @@ static MethodInfo GetShadowSetter(TypeModel model, PropertyInfo property)
public override void Write(object value, ProtoWriter dest)
{
Helpers.DebugAssert(value != null);
value = property.GetValue(value, null);
//value = property.GetValue(value, null);
value = property.GetGetMethod(true).Invoke(value, null);
if(value != null) Tail.Write(value, dest);
}
public override object Read(object value, ProtoReader source)
{
Helpers.DebugAssert(value != null);

object oldVal = Tail.RequiresOldValue ? property.GetValue(value, null) : null;
//object oldVal = Tail.RequiresOldValue ? property.GetValue(value, null) : null;
object oldVal = Tail.RequiresOldValue ? property.GetGetMethod(true).Invoke(value, null) : null;
object newVal = Tail.Read(oldVal, source);
if (readOptionsWriteValue && newVal != null) // if the tail returns a null, intepret that as *no assign*
{
Expand Down
39 changes: 32 additions & 7 deletions protobuf-net/Serializers/SurrogateSerializer.cs
Expand Up @@ -31,7 +31,7 @@ sealed class SurrogateSerializer : IProtoTypeSerializer
private readonly MethodInfo toTail, fromTail;
IProtoTypeSerializer rootTail;

public SurrogateSerializer(Type forType, Type declaredType, IProtoTypeSerializer rootTail)
public SurrogateSerializer(TypeModel model, Type forType, Type declaredType, IProtoTypeSerializer rootTail)
{
Helpers.DebugAssert(forType != null, "forType");
Helpers.DebugAssert(declaredType != null, "declaredType");
Expand All @@ -42,10 +42,10 @@ public SurrogateSerializer(Type forType, Type declaredType, IProtoTypeSerializer
this.forType = forType;
this.declaredType = declaredType;
this.rootTail = rootTail;
toTail = GetConversion(true);
fromTail = GetConversion(false);
toTail = GetConversion(model, true);
fromTail = GetConversion(model, false);
}
private static bool HasCast(Type type, Type from, Type to, out MethodInfo op)
private static bool HasCast(TypeModel model, Type type, Type from, Type to, out MethodInfo op)
{
#if WINRT
System.Collections.Generic.List<MethodInfo> list = new System.Collections.Generic.List<MethodInfo>();
Expand All @@ -58,14 +58,39 @@ private static bool HasCast(Type type, Type from, Type to, out MethodInfo op)
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo[] found = type.GetMethods(flags);
#endif
ParameterInfo[] paramTypes;
Type convertAttributeType = null;
for (int i = 0; i < found.Length; i++)
{
MethodInfo m = found[i];
if (m.ReturnType != to) continue;
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
if (convertAttributeType == null)
{
convertAttributeType = model.MapType(typeof(ProtoConverterAttribute), false);
if (convertAttributeType == null)
{ // attribute isn't defined in the source assembly: stop looking
break;
}
}
if (m.IsDefined(convertAttributeType, true))
{
op = m;
return true;
}
}
}

for(int i = 0 ; i < found.Length ; i++)
{
MethodInfo m = found[i];
if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
{
continue;
}
ParameterInfo[] paramTypes = m.GetParameters();
paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
op = m;
Expand All @@ -76,12 +101,12 @@ private static bool HasCast(Type type, Type from, Type to, out MethodInfo op)
return false;
}

public MethodInfo GetConversion(bool toTail)
public MethodInfo GetConversion(TypeModel model, bool toTail)
{
Type to = toTail ? declaredType : forType;
Type from = toTail ? forType : declaredType;
MethodInfo op;
if (HasCast(declaredType, from, to, out op) || HasCast(forType, from, to, out op))
if (HasCast(model, declaredType, from, to, out op) || HasCast(model, forType, from, to, out op))
{
return op;
}
Expand Down
3 changes: 2 additions & 1 deletion protobuf-net/Serializers/TupleSerializer.cs
Expand Up @@ -93,7 +93,8 @@ private object GetValue(object obj, int index)
{
if (obj == null)
return Helpers.IsValueType(prop.PropertyType) ? Activator.CreateInstance(prop.PropertyType) : null;
return prop.GetValue(obj, null);
//return prop.GetValue(obj, null);
return prop.GetGetMethod(true).Invoke(obj, null);
}
else if ((field = members[index] as FieldInfo) != null)
{
Expand Down
3 changes: 2 additions & 1 deletion protobuf-net/protobuf-net.csproj
Expand Up @@ -130,7 +130,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Unity|AnyCPU'">
<OutputPath>bin\Unity\</OutputPath>
<DefineConstants>TRACE;FEAT_COMPILER PLAT_BINARYFORMATTER PLAT_XMLSERIALIZER PLAT_NO_INTERLOCKED FEAT_SAFE</DefineConstants>
<DefineConstants>TRACE;PLAT_BINARYFORMATTER PLAT_XMLSERIALIZER PLAT_NO_INTERLOCKED FEAT_SAFE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>bin\Net20\protobuf-net.xml</DocumentationFile>
<Optimize>true</Optimize>
Expand Down Expand Up @@ -187,6 +187,7 @@
<Compile Include="Compiler\CompilerDelegates.cs" />
<Compile Include="Compiler\CompilerContext.cs" />
<Compile Include="Compiler\Local.cs" />
<Compile Include="ProtoConverterAttribute.cs" />
<Compile Include="DataFormat.cs">
<SubType>Code</SubType>
</Compile>
Expand Down

0 comments on commit 4eddeeb

Please sign in to comment.