Наследование: MemberSignature
Пример #1
0
        private void GenerateDataObjectClass(string className, List<Parameter> parameters, string @namespace, bool isValueType, Type dataObjecDataType = null)
        {
            if (@namespace != null)
            {
                WriteLine("namespace  {0}", @namespace);
                WriteStartBraceIndent();
            }

            var structclass = (isValueType) ? "struct" : "class";

            var baseDataObjects = GetBaseDataObjects(dataObjecDataType);
            var baseDataObjectCount = (baseDataObjects == null) ? 0 : baseDataObjects.Count;
            var baseDataObject = (baseDataObjectCount == 0) ? null : baseDataObjects[0];

            if (baseDataObject != null)
            {
                WriteLine("public {0} {1} : {2}", structclass, className, GetStubsClassName(baseDataObject, true));
            }
            else
            {
                var @interface = (isValueType) ? "IDataObject" : "IObservableDataObject";
                WriteLine("public {0} {1} : {2}", structclass, className, @interface);
            }

            WriteStartBraceIndent();

            // Generate fields
            if (!isValueType)
            {
                WriteLine("public class Reference : {0}, IDataObjectReference", className);
                WriteStartBraceIndent();
                WriteLine("public RemotingPeer Peer { get; private set; }");
                WriteLine("public int RemoteId { get; private set; }");
                WriteLine("public ReferenceManager ReferenceManager { get; private set; }");
                NewLine();
                WriteLine("public Reference(RemotingPeer peer, int remoteId, ReferenceManager referenceManager)");
                WriteStartBraceIndent();
                WriteLine("Peer = peer;");
                WriteLine("RemoteId = remoteId;");
                WriteLine("ReferenceManager = referenceManager;");
                WriteCloseBraceIndent();
                WriteCloseBraceIndent();
                NewLine();
                if (baseDataObject == null)
                {
                    WriteLine("private event Action<Type, int> propertyChanged;");
                    WriteLine("event Action<Type,int> IObservableDataObject.PropertyChanged");
                    WriteStartBraceIndent();
                    WriteLine("add { propertyChanged += value; }");
                    WriteLine("remove { propertyChanged -= value; }");
                    WriteCloseBraceIndent();
                    NewLine();
                    WriteLine("protected void OnPropertyChanged(Type type, int propertyId)");
                    WriteStartBraceIndent();
                    WriteLine("if(propertyChanged != null)");
                    WriteLineIndent("propertyChanged(type, propertyId);");
                    WriteCloseBraceIndent();
                    NewLine();
                }
                WriteLine("private BitField changedProperties;");
                NewLine();
                foreach (var param in parameters)
                {
                    var backingFieldName = "__" + param.Name;
                    var paramTypeName = GetTypeName(param.ParameterType);

                    if (param.IsImplementedProperty)
                    {
                        WriteLine("private {0} {1} {{ get; set; }}", paramTypeName, backingFieldName);

                        var typeSig = new TypeSignature(param.ParameterType);
                        var declaringTypeSig = new TypeSignature(dataObjecDataType);

                        GenerationContext.MemberClones.Add(new MemberClone
                        {
                            OriginMember = new PropertySignature(typeSig, declaringTypeSig, param.Name),
                            Name = backingFieldName,
                            AccessModifier = AccessModifiers.Private,
                            NoCustomAttributes = true
                        });

                        var setParams = new List<ParameterSignature> {new ParameterSignature(typeSig, "value")};
                        var getMethodSig = new MethodSignature(typeSig, declaringTypeSig, "get_"+backingFieldName, new List<ParameterSignature>());
                        var setMethodSig = new MethodSignature(new TypeSignature(typeof(void)), declaringTypeSig, "set_"+backingFieldName, setParams);

                        GenerationContext.MemberOptions.Add(getMethodSig, Weaver.MemberOptions.UseOriginInstructions);
                        GenerationContext.MemberOptions.Add(setMethodSig, Weaver.MemberOptions.UseOriginInstructions);
                    }
                    else
                    {
                        WriteLine("private {0} {1};", paramTypeName, backingFieldName);
                    }

                    WriteLine("public {0} {1}", paramTypeName, ToTitleCase(param.Name));
                    WriteStartBraceIndent();
                    WriteLine("get {{ return {0}; }}", backingFieldName);
                    WriteLine("set");
                    WriteStartBraceIndent();
                    WriteLine("if( value == {0})", backingFieldName);
                    WriteLineIndent("return;");
                    NewLine();
                    WriteLine("{0} = value;", backingFieldName);
                    NewLine();
                    WriteLine("changedProperties.SetBit({0});", param.Id);
                    NewLine();
                    WriteLine("OnPropertyChanged(typeof({0}), {1});", className, param.Id);
                    WriteCloseBraceIndent();
                    WriteCloseBraceIndent();
                    NewLine();
                }

                WriteLine("public bool IsReference{ get; set; }");
                NewLine();

                WriteLine("public unsafe void GetResetChanges(BitField* bitFields)");
                WriteStartBraceIndent();
                WriteLine("bitFields[0] = changedProperties;");
                WriteLine("changedProperties.Reset();");
                if (baseDataObject != null)
                {
                    NewLine();
                    WriteLine("(({0}) (object) this).GetResetChanges(bitFields++);", GetStubsClassName(baseDataObject, true));
                }
                WriteCloseBraceIndent();
                NewLine();
            }
            else
            {
                foreach (var param in parameters)
                {
                    var paramTypeName = GetTypeName(param.ParameterType);

                    WriteLine("public {0} {1};", paramTypeName, ToTitleCase(param.Name));

                    if(IsDelegate(param.ParameterType))
                        GenerationContext.Delegates.Add(param.ParameterType);

                    NewLine();
                }
            }

            WriteLine("public int BaseDataObjectCount {{ get {{ return {0}; }} }}", baseDataObjectCount);
            NewLine();

            // Generate write methods
            GenerateDataObjectWriteBitField(parameters, baseDataObject);
            GenerateDataObjectWrite(className, baseDataObjectCount > 0, isValueType);
            NewLine();

            // Generate read method
            GenerateDataObjectRead(className,  baseDataObjectCount > 0, isValueType, parameters);

            WriteCloseBraceIndent();
            if (@namespace != null)
                WriteCloseBraceIndent();
        }
Пример #2
0
 public MemberWithReturnSignature(TypeSignature returnType, TypeSignature declaringType, string name)
     : base(declaringType, name)
 {
     ReturnType = returnType;
 }
Пример #3
0
 protected MemberSignature(TypeSignature declaringType, string name)
 {
     DeclaringType = declaringType;
     Name = name;
 }
Пример #4
0
 public TypeSignature(TypeSignature declaringType, string name)
     : base(declaringType, name)
 {
     Namespace = null;
 }
Пример #5
0
 public TypeSignatureCollection(IList<TypeReference> types)
 {
     Types = new TypeSignature[types.Count()];
     for (int i = 0; i < types.Count(); i++)
         Types[i] = new TypeSignature(types[i]);
 }
Пример #6
0
 public PropertySignature(TypeSignature propertyType, TypeSignature declaringType, string name)
     : base(declaringType, name)
 {
     PropertyType = propertyType;
 }
Пример #7
0
 public ParameterSignature(TypeSignature paramType, string name)
 {
     ParamType = paramType;
     Name = name;
 }
Пример #8
0
        public MethodSignature(MethodInfo method)
            : base(new TypeSignature(method.DeclaringType), method.Name)
        {
            ReturnType = new TypeSignature(method.ReturnType);

            Parameters = new List<ParameterSignature>();
            foreach (var param in method.GetParameters())
                Parameters.Add(new ParameterSignature(param));
        }
Пример #9
0
 public FieldSignature(TypeSignature fieldType, TypeSignature declaringType, string name)
     : base(declaringType, name)
 {
     FieldType = fieldType;
 }
Пример #10
0
 public MethodSignature(TypeSignature returnType, TypeSignature declaringType, string name, List<ParameterSignature> parameters )
     : base(declaringType, name)
 {
     ReturnType = returnType;
     Parameters = parameters;
 }